/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.config.javabeans;

import java.io.Serializable;

import java.util.HashMap;
import java.util.Map;


/**
 * Class corresponding to the "ressources" element of the profiles_config.xml file.
 * This contains resources sepcific to a profile.
 */
public class JBRessources implements Serializable
{
    /** List of resources (JBRessource). */
    private Map ressourceMap = new HashMap();

    /** Creates new JBRessources. */
    public JBRessources()
    {
    }

    /**
     * Returns the list of resources.
     * @return list of resources
     */
    public Map getRessourceMap()
    {
        return ressourceMap;
    }

    /**
     * Adds a resource to list.
     *
     * @param ressource resource to add
     */
    public void addRessource(JBRessource ressource)
    {
        String key = ressource.getName().trim().toLowerCase();
        ressourceMap.put(key, ressource);
    }

    /**
     * Gets a resource from its name.
     *
     * @param name resource name
     *
     * @return resource descriptor
     */
    public JBRessource findRessourceByName(String name)
    {
        // rendre case insensitive en mettant le param en lowercase
        String key = name.trim().toLowerCase();

        return (JBRessource) ressourceMap.get(key);
    }

    /**
     * Displays the resources.
     *
     * @return String representation of the list of resources
     */
    @Override
	public String toString()
    {
        StringBuffer buf = new StringBuffer();
        java.util.Iterator it = null;

        if (ressourceMap != null)
        {
            buf.append("Map components of ressourceMap = ");
            buf.append(System.getProperty("line.separator"));
            it = ressourceMap.values().iterator();

            while (it.hasNext())
            {
                buf.append("...");
                buf.append(it.next());
                buf.append(System.getProperty("line.separator"));
            }
        }

        return buf.toString();
    }

    // end of toString method
}
